home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _0EDD118E8E8842AF9271F281D2D4F98D < prev    next >
Encoding:
Text File  |  2002-06-17  |  4.9 KB  |  263 lines

  1. // Copyright (C) 2001-2002 Raven Software
  2. //
  3.  
  4. // this file holds commands that can be executed by the server console, but not remote clients
  5.  
  6. #include "g_local.h"
  7.  
  8. char    *ConcatArgs( int start );
  9.  
  10. /*
  11. ===================
  12. Svcmd_EntityList_f
  13. ===================
  14. */
  15. void    Svcmd_EntityList_f (void) {
  16.     int            e;
  17.     gentity_t        *check;
  18.  
  19.     check = g_entities+1;
  20.     for (e = 1; e < level.num_entities ; e++, check++) {
  21.         if ( !check->inuse ) {
  22.             continue;
  23.         }
  24.         Com_Printf("%3i:", e);
  25.         switch ( check->s.eType ) {
  26.         case ET_GENERAL:
  27.             Com_Printf("ET_GENERAL          ");
  28.             break;
  29.         case ET_PLAYER:
  30.             Com_Printf("ET_PLAYER           ");
  31.             break;
  32.         case ET_ITEM:
  33.             Com_Printf("ET_ITEM             ");
  34.             break;
  35.         case ET_MISSILE:
  36.             Com_Printf("ET_MISSILE          ");
  37.             break;
  38.         case ET_MOVER:
  39.             Com_Printf("ET_MOVER            ");
  40.             break;
  41.         case ET_BEAM:
  42.             Com_Printf("ET_BEAM             ");
  43.             break;
  44.         case ET_PORTAL:
  45.             Com_Printf("ET_PORTAL           ");
  46.             break;
  47.         case ET_SPEAKER:
  48.             Com_Printf("ET_SPEAKER          ");
  49.             break;
  50.         case ET_PUSH_TRIGGER:
  51.             Com_Printf("ET_PUSH_TRIGGER     ");
  52.             break;
  53.         case ET_TELEPORT_TRIGGER:
  54.             Com_Printf("ET_TELEPORT_TRIGGER ");
  55.             break;
  56.         case ET_INVISIBLE:
  57.             Com_Printf("ET_INVISIBLE        ");
  58.             break;
  59.         case ET_GRAPPLE:
  60.             Com_Printf("ET_GRAPPLE          ");
  61.             break;
  62.         default:
  63.             Com_Printf("%3i                 ", check->s.eType);
  64.             break;
  65.         }
  66.  
  67.         if ( check->classname ) {
  68.             Com_Printf("%s", check->classname);
  69.         }
  70.         Com_Printf("\n");
  71.     }
  72. }
  73.  
  74.  
  75. void Svcmd_ExtendTime_f (void) 
  76. {
  77.     char str[MAX_TOKEN_CHARS];
  78.     int     time;
  79.  
  80.     if ( trap_Argc() < 2 ) 
  81.     {
  82.         Com_Printf("Usage:  extendtime <minutes>\n");
  83.         return;
  84.     }
  85.  
  86.     trap_Argv( 1, str, sizeof( str ) );
  87.  
  88.     time = atoi(str);
  89.     level.timeExtension += time;
  90.  
  91.     G_LogPrintf ( "timelimit extended by %d minutes\n", time );
  92.  
  93.     trap_SendServerCommand( -1, va("print \"timelimit extended by %d minutes\n\"", time) );
  94. }
  95.  
  96. void Svcmd_AutoKickList_f ( void )
  97. {
  98.     int i;
  99.  
  100.     for ( i = 0; i < level.autokickedCount; i ++ )
  101.     {
  102.         Com_Printf ( "%16s - %s\n", level.autokickedIP[i], level.autokickedName[i] );
  103.     }
  104. }
  105.  
  106. gclient_t    *ClientForString( const char *s ) {
  107.     gclient_t    *cl;
  108.     int            i;
  109.     int            idnum;
  110.  
  111.     // numeric values are just slot numbers
  112.     if ( s[0] >= '0' && s[0] <= '9' ) {
  113.         idnum = atoi( s );
  114.         if ( idnum < 0 || idnum >= level.maxclients ) {
  115.             Com_Printf( "Bad client slot: %i\n", idnum );
  116.             return NULL;
  117.         }
  118.  
  119.         cl = &level.clients[idnum];
  120.         if ( cl->pers.connected == CON_DISCONNECTED ) {
  121.             Com_Printf( "Client %i is not connected\n", idnum );
  122.             return NULL;
  123.         }
  124.         return cl;
  125.     }
  126.  
  127.     // check for a name match
  128.     for ( i=0 ; i < level.maxclients ; i++ ) {
  129.         cl = &level.clients[i];
  130.         if ( cl->pers.connected == CON_DISCONNECTED ) {
  131.             continue;
  132.         }
  133.         if ( !Q_stricmp( cl->pers.netname, s ) ) {
  134.             return cl;
  135.         }
  136.     }
  137.  
  138.     Com_Printf( "User %s is not on the server\n", s );
  139.  
  140.     return NULL;
  141. }
  142.  
  143. /*
  144. ===================
  145. Svcmd_ForceTeam_f
  146.  
  147. forceteam <player> <team>
  148. ===================
  149. */
  150. void Svcmd_ForceTeam_f( void ) 
  151. {
  152.     gclient_t    *cl;
  153.     char        str[MAX_TOKEN_CHARS];
  154.  
  155.     // find the player
  156.     trap_Argv( 1, str, sizeof( str ) );
  157.     cl = ClientForString( str );
  158.     if ( !cl ) 
  159.     {
  160.         return;
  161.     }
  162.  
  163.     // set the team
  164.     trap_Argv( 2, str, sizeof( str ) );
  165.     SetTeam( &g_entities[cl - level.clients], str, NULL );
  166. }
  167.  
  168. /*
  169. ===================
  170. Svcmd_CancelVote_f
  171.  
  172. cancels the vote in progress
  173. ===================
  174. */
  175. void Svcmd_CancelVote_f ( void )
  176. {
  177.     level.voteTime = 0;
  178.  
  179.     trap_SetConfigstring( CS_VOTE_TIME, "" );    
  180.  
  181.     trap_SendServerCommand( -1, "print \"Vote cancelled by admin.\n\"" );
  182. }
  183.  
  184. /*
  185. =================
  186. ConsoleCommand
  187. =================
  188. */
  189. qboolean ConsoleCommand( void ) 
  190. {
  191.     char cmd[MAX_TOKEN_CHARS];
  192.  
  193.     trap_Argv( 0, cmd, sizeof( cmd ) );
  194.  
  195.     if ( Q_stricmp (cmd, "entitylist") == 0 ) 
  196.     {
  197.         Svcmd_EntityList_f();
  198.         return qtrue;
  199.     }
  200.  
  201.     if ( Q_stricmp (cmd, "forceteam") == 0 ) 
  202.     {
  203.         Svcmd_ForceTeam_f();
  204.         return qtrue;
  205.     }
  206.  
  207.     if ( Q_stricmp ( cmd, "cancelvote" ) == 0 )
  208.     {
  209.         Svcmd_CancelVote_f();
  210.         return qtrue;
  211.     }
  212.  
  213. #ifdef _SOF2_BOTS
  214.  
  215.     if (Q_stricmp (cmd, "addbot") == 0) 
  216.     {
  217.         Svcmd_AddBot_f();
  218.         return qtrue;
  219.     }
  220.  
  221.     if (Q_stricmp (cmd, "botlist") == 0) 
  222.     {
  223.         Svcmd_BotList_f();
  224.         return qtrue;
  225.     }
  226.  
  227. #endif
  228.  
  229.     if (Q_stricmp (cmd, "gametype_restart" ) == 0 )
  230.     {
  231.         G_ResetGametype ( );
  232.         return qtrue;
  233.     }
  234.  
  235.     if (Q_stricmp (cmd, "extendtime" ) == 0 )
  236.     {
  237.         Svcmd_ExtendTime_f();
  238.         return qtrue;
  239.     }
  240.  
  241.     if ( Q_stricmp ( cmd, "autokicklist" ) == 0 )
  242.     {
  243.         Svcmd_AutoKickList_f();
  244.         return qtrue;
  245.     }
  246.  
  247.     if (g_dedicated.integer) 
  248.     {
  249.         if (Q_stricmp (cmd, "say") == 0) 
  250.         {
  251.             trap_SendServerCommand( -1, va("chat -1 \"server: %s\n\"", ConcatArgs(1) ) );
  252.             return qtrue;
  253.         }
  254.  
  255.         // everything else will also be printed as a say command
  256.         trap_SendServerCommand( -1, va("chat -1 \"server: %s\n\"", ConcatArgs(0) ) );
  257.         return qtrue;
  258.     }
  259.  
  260.     return qfalse;
  261. }
  262.  
  263.